﻿using System;

namespace Microsoft.Media.WebVTT
{
    internal static class UnicodeExtensions
    {
        public static bool IsLCat(int c)
        {
            return (
                (c >= 0x0041 && c <= 0x005A) ||
                (c >= 0x0061 && c <= 0x007A) ||
                (c == 0x00AA) ||
                (c == 0x00B5) ||
                (c == 0x00BA) ||
                (c >= 0x00C0 && c <= 0x00D6) ||
                (c >= 0x00D8 && c <= 0x00F6) ||
                (c >= 0x00F8 && c <= 0x0220) ||
                (c >= 0x0222 && c <= 0x0233) ||
                (c >= 0x0250 && c <= 0x02AD) ||
                (c >= 0x02B0 && c <= 0x02B8) ||
                (c >= 0x02BB && c <= 0x02C1) ||
                (c >= 0x02D0 && c <= 0x02D1) ||
                (c >= 0x02E0 && c <= 0x02E4) ||
                (c == 0x02EE) ||
                (c == 0x037A) ||
                (c == 0x0386) ||
                (c >= 0x0388 && c <= 0x038A) ||
                (c == 0x038C) ||
                (c >= 0x038E && c <= 0x03A1) ||
                (c >= 0x03A3 && c <= 0x03CE) ||
                (c >= 0x03D0 && c <= 0x03F5) ||
                (c >= 0x0400 && c <= 0x0482) ||
                (c >= 0x048A && c <= 0x04CE) ||
                (c >= 0x04D0 && c <= 0x04F5) ||
                (c >= 0x04F8 && c <= 0x04F9) ||
                (c >= 0x0500 && c <= 0x050F) ||
                (c >= 0x0531 && c <= 0x0556) ||
                (c >= 0x0559 && c <= 0x055F) ||
                (c >= 0x0561 && c <= 0x0587) ||
                (c == 0x0589) ||
                (c == 0x0903) ||
                (c >= 0x0905 && c <= 0x0939) ||
                (c >= 0x093D && c <= 0x0940) ||
                (c >= 0x0949 && c <= 0x094C) ||
                (c == 0x0950) ||
                (c >= 0x0958 && c <= 0x0961) ||
                (c >= 0x0964 && c <= 0x0970) ||
                (c >= 0x0982 && c <= 0x0983) ||
                (c >= 0x0985 && c <= 0x098C) ||
                (c >= 0x098F && c <= 0x0990) ||
                (c >= 0x0993 && c <= 0x09A8) ||
                (c >= 0x09AA && c <= 0x09B0) ||
                (c == 0x09B2) ||
                (c >= 0x09B6 && c <= 0x09B9) ||
                (c >= 0x09BE && c <= 0x09C0) ||
                (c >= 0x09C7 && c <= 0x09C8) ||
                (c >= 0x09CB && c <= 0x09CC) ||
                (c == 0x09D7) ||
                (c >= 0x09DC && c <= 0x09DD) ||
                (c >= 0x09DF && c <= 0x09E1) ||
                (c >= 0x09E6 && c <= 0x09F1) ||
                (c >= 0x09F4 && c <= 0x09FA) ||
                (c >= 0x0A05 && c <= 0x0A0A) ||
                (c >= 0x0A0F && c <= 0x0A10) ||
                (c >= 0x0A13 && c <= 0x0A28) ||
                (c >= 0x0A2A && c <= 0x0A30) ||
                (c >= 0x0A32 && c <= 0x0A33) ||
                (c >= 0x0A35 && c <= 0x0A36) ||
                (c >= 0x0A38 && c <= 0x0A39) ||
                (c >= 0x0A3E && c <= 0x0A40) ||
                (c >= 0x0A59 && c <= 0x0A5C) ||
                (c == 0x0A5E) ||
                (c >= 0x0A66 && c <= 0x0A6F) ||
                (c >= 0x0A72 && c <= 0x0A74) ||
                (c == 0x0A83) ||
                (c >= 0x0A85 && c <= 0x0A8B) ||
                (c == 0x0A8D) ||
                (c >= 0x0A8F && c <= 0x0A91) ||
                (c >= 0x0A93 && c <= 0x0AA8) ||
                (c >= 0x0AAA && c <= 0x0AB0) ||
                (c >= 0x0AB2 && c <= 0x0AB3) ||
                (c >= 0x0AB5 && c <= 0x0AB9) ||
                (c >= 0x0ABD && c <= 0x0AC0) ||
                (c == 0x0AC9) ||
                (c >= 0x0ACB && c <= 0x0ACC) ||
                (c == 0x0AD0) ||
                (c == 0x0AE0) ||
                (c >= 0x0AE6 && c <= 0x0AEF) ||
                (c >= 0x0B02 && c <= 0x0B03) ||
                (c >= 0x0B05 && c <= 0x0B0C) ||
                (c >= 0x0B0F && c <= 0x0B10) ||
                (c >= 0x0B13 && c <= 0x0B28) ||
                (c >= 0x0B2A && c <= 0x0B30) ||
                (c >= 0x0B32 && c <= 0x0B33) ||
                (c >= 0x0B36 && c <= 0x0B39) ||
                (c >= 0x0B3D && c <= 0x0B3E) ||
                (c == 0x0B40) ||
                (c >= 0x0B47 && c <= 0x0B48) ||
                (c >= 0x0B4B && c <= 0x0B4C) ||
                (c == 0x0B57) ||
                (c >= 0x0B5C && c <= 0x0B5D) ||
                (c >= 0x0B5F && c <= 0x0B61) ||
                (c >= 0x0B66 && c <= 0x0B70) ||
                (c == 0x0B83) ||
                (c >= 0x0B85 && c <= 0x0B8A) ||
                (c >= 0x0B8E && c <= 0x0B90) ||
                (c >= 0x0B92 && c <= 0x0B95) ||
                (c >= 0x0B99 && c <= 0x0B9A) ||
                (c == 0x0B9C) ||
                (c >= 0x0B9E && c <= 0x0B9F) ||
                (c >= 0x0BA3 && c <= 0x0BA4) ||
                (c >= 0x0BA8 && c <= 0x0BAA) ||
                (c >= 0x0BAE && c <= 0x0BB5) ||
                (c >= 0x0BB7 && c <= 0x0BB9) ||
                (c >= 0x0BBE && c <= 0x0BBF) ||
                (c >= 0x0BC1 && c <= 0x0BC2) ||
                (c >= 0x0BC6 && c <= 0x0BC8) ||
                (c >= 0x0BCA && c <= 0x0BCC) ||
                (c == 0x0BD7) ||
                (c >= 0x0BE7 && c <= 0x0BF2) ||
                (c >= 0x0C01 && c <= 0x0C03) ||
                (c >= 0x0C05 && c <= 0x0C0C) ||
                (c >= 0x0C0E && c <= 0x0C10) ||
                (c >= 0x0C12 && c <= 0x0C28) ||
                (c >= 0x0C2A && c <= 0x0C33) ||
                (c >= 0x0C35 && c <= 0x0C39) ||
                (c >= 0x0C41 && c <= 0x0C44) ||
                (c >= 0x0C60 && c <= 0x0C61) ||
                (c >= 0x0C66 && c <= 0x0C6F) ||
                (c >= 0x0C82 && c <= 0x0C83) ||
                (c >= 0x0C85 && c <= 0x0C8C) ||
                (c >= 0x0C8E && c <= 0x0C90) ||
                (c >= 0x0C92 && c <= 0x0CA8) ||
                (c >= 0x0CAA && c <= 0x0CB3) ||
                (c >= 0x0CB5 && c <= 0x0CB9) ||
                (c == 0x0CBE) ||
                (c >= 0x0CC0 && c <= 0x0CC4) ||
                (c >= 0x0CC7 && c <= 0x0CC8) ||
                (c >= 0x0CCA && c <= 0x0CCB) ||
                (c >= 0x0CD5 && c <= 0x0CD6) ||
                (c == 0x0CDE) ||
                (c >= 0x0CE0 && c <= 0x0CE1) ||
                (c >= 0x0CE6 && c <= 0x0CEF) ||
                (c >= 0x0D02 && c <= 0x0D03) ||
                (c >= 0x0D05 && c <= 0x0D0C) ||
                (c >= 0x0D0E && c <= 0x0D10) ||
                (c >= 0x0D12 && c <= 0x0D28) ||
                (c >= 0x0D2A && c <= 0x0D39) ||
                (c >= 0x0D3E && c <= 0x0D40) ||
                (c >= 0x0D46 && c <= 0x0D48) ||
                (c >= 0x0D4A && c <= 0x0D4C) ||
                (c == 0x0D57) ||
                (c >= 0x0D60 && c <= 0x0D61) ||
                (c >= 0x0D66 && c <= 0x0D6F) ||
                (c >= 0x0D82 && c <= 0x0D83) ||
                (c >= 0x0D85 && c <= 0x0D96) ||
                (c >= 0x0D9A && c <= 0x0DB1) ||
                (c >= 0x0DB3 && c <= 0x0DBB) ||
                (c == 0x0DBD) ||
                (c >= 0x0DC0 && c <= 0x0DC6) ||
                (c >= 0x0DCF && c <= 0x0DD1) ||
                (c >= 0x0DD8 && c <= 0x0DDF) ||
                (c >= 0x0DF2 && c <= 0x0DF4) ||
                (c >= 0x0E01 && c <= 0x0E30) ||
                (c >= 0x0E32 && c <= 0x0E33) ||
                (c >= 0x0E40 && c <= 0x0E46) ||
                (c >= 0x0E4F && c <= 0x0E5B) ||
                (c >= 0x0E81 && c <= 0x0E82) ||
                (c == 0x0E84) ||
                (c >= 0x0E87 && c <= 0x0E88) ||
                (c == 0x0E8A) ||
                (c == 0x0E8D) ||
                (c >= 0x0E94 && c <= 0x0E97) ||
                (c >= 0x0E99 && c <= 0x0E9F) ||
                (c >= 0x0EA1 && c <= 0x0EA3) ||
                (c == 0x0EA5) ||
                (c == 0x0EA7) ||
                (c >= 0x0EAA && c <= 0x0EAB) ||
                (c >= 0x0EAD && c <= 0x0EB0) ||
                (c >= 0x0EB2 && c <= 0x0EB3) ||
                (c == 0x0EBD) ||
                (c >= 0x0EC0 && c <= 0x0EC4) ||
                (c == 0x0EC6) ||
                (c >= 0x0ED0 && c <= 0x0ED9) ||
                (c >= 0x0EDC && c <= 0x0EDD) ||
                (c >= 0x0F00 && c <= 0x0F17) ||
                (c >= 0x0F1A && c <= 0x0F34) ||
                (c == 0x0F36) ||
                (c == 0x0F38) ||
                (c >= 0x0F3E && c <= 0x0F47) ||
                (c >= 0x0F49 && c <= 0x0F6A) ||
                (c == 0x0F7F) ||
                (c == 0x0F85) ||
                (c >= 0x0F88 && c <= 0x0F8B) ||
                (c >= 0x0FBE && c <= 0x0FC5) ||
                (c >= 0x0FC7 && c <= 0x0FCC) ||
                (c == 0x0FCF) ||
                (c >= 0x1000 && c <= 0x1021) ||
                (c >= 0x1023 && c <= 0x1027) ||
                (c >= 0x1029 && c <= 0x102A) ||
                (c == 0x102C) ||
                (c == 0x1031) ||
                (c == 0x1038) ||
                (c >= 0x1040 && c <= 0x1057) ||
                (c >= 0x10A0 && c <= 0x10C5) ||
                (c >= 0x10D0 && c <= 0x10F8) ||
                (c == 0x10FB) ||
                (c >= 0x1100 && c <= 0x1159) ||
                (c >= 0x115F && c <= 0x11A2) ||
                (c >= 0x11A8 && c <= 0x11F9) ||
                (c >= 0x1200 && c <= 0x1206) ||
                (c >= 0x1208 && c <= 0x1246) ||
                (c == 0x1248) ||
                (c >= 0x124A && c <= 0x124D) ||
                (c >= 0x1250 && c <= 0x1256) ||
                (c == 0x1258) ||
                (c >= 0x125A && c <= 0x125D) ||
                (c >= 0x1260 && c <= 0x1286) ||
                (c == 0x1288) ||
                (c >= 0x128A && c <= 0x128D) ||
                (c >= 0x1290 && c <= 0x12AE) ||
                (c == 0x12B0) ||
                (c >= 0x12B2 && c <= 0x12B5) ||
                (c >= 0x12B8 && c <= 0x12BE) ||
                (c == 0x12C0) ||
                (c >= 0x12C2 && c <= 0x12C5) ||
                (c >= 0x12C8 && c <= 0x12CE) ||
                (c >= 0x12D0 && c <= 0x12D6) ||
                (c >= 0x12D8 && c <= 0x12EE) ||
                (c >= 0x12F0 && c <= 0x130E) ||
                (c == 0x1310) ||
                (c >= 0x1312 && c <= 0x1315) ||
                (c >= 0x1318 && c <= 0x131E) ||
                (c >= 0x1320 && c <= 0x1346) ||
                (c >= 0x1348 && c <= 0x135A) ||
                (c >= 0x1361 && c <= 0x137C) ||
                (c >= 0x13A0 && c <= 0x13F4) ||
                (c >= 0x1401 && c <= 0x1676) ||
                (c >= 0x1681 && c <= 0x169A) ||
                (c >= 0x16A0 && c <= 0x16F0) ||
                (c >= 0x1700 && c <= 0x170C) ||
                (c >= 0x170E && c <= 0x1711) ||
                (c >= 0x1720 && c <= 0x1731) ||
                (c >= 0x1735 && c <= 0x1736) ||
                (c >= 0x1740 && c <= 0x1751) ||
                (c >= 0x1760 && c <= 0x176C) ||
                (c >= 0x176E && c <= 0x1770) ||
                (c >= 0x1780 && c <= 0x17B6) ||
                (c >= 0x17BE && c <= 0x17C5) ||
                (c >= 0x17C7 && c <= 0x17C8) ||
                (c >= 0x17D4 && c <= 0x17DA) ||
                (c == 0x17DC) ||
                (c >= 0x17E0 && c <= 0x17E9) ||
                (c >= 0x1810 && c <= 0x1819) ||
                (c >= 0x1820 && c <= 0x1877) ||
                (c >= 0x1880 && c <= 0x18A8) ||
                (c >= 0x1E00 && c <= 0x1E9B) ||
                (c >= 0x1EA0 && c <= 0x1EF9) ||
                (c >= 0x1F00 && c <= 0x1F15) ||
                (c >= 0x1F18 && c <= 0x1F1D) ||
                (c >= 0x1F20 && c <= 0x1F45) ||
                (c >= 0x1F48 && c <= 0x1F4D) ||
                (c >= 0x1F50 && c <= 0x1F57) ||
                (c == 0x1F59) ||
                (c == 0x1F5B) ||
                (c == 0x1F5D) ||
                (c >= 0x1F5F && c <= 0x1F7D) ||
                (c >= 0x1F80 && c <= 0x1FB4) ||
                (c >= 0x1FB6 && c <= 0x1FBC) ||
                (c == 0x1FBE) ||
                (c >= 0x1FC2 && c <= 0x1FC4) ||
                (c >= 0x1FC6 && c <= 0x1FCC) ||
                (c >= 0x1FD0 && c <= 0x1FD3) ||
                (c >= 0x1FD6 && c <= 0x1FDB) ||
                (c >= 0x1FE0 && c <= 0x1FEC) ||
                (c >= 0x1FF2 && c <= 0x1FF4) ||
                (c >= 0x1FF6 && c <= 0x1FFC) ||
                (c == 0x200E) ||
                (c == 0x2071) ||
                (c == 0x207F) ||
                (c == 0x2102) ||
                (c == 0x2107) ||
                (c >= 0x210A && c <= 0x2113) ||
                (c == 0x2115) ||
                (c >= 0x2119 && c <= 0x211D) ||
                (c == 0x2124) ||
                (c == 0x2126) ||
                (c == 0x2128) ||
                (c >= 0x212A && c <= 0x212D) ||
                (c >= 0x212F && c <= 0x2131) ||
                (c >= 0x2133 && c <= 0x2139) ||
                (c >= 0x213D && c <= 0x213F) ||
                (c >= 0x2145 && c <= 0x2149) ||
                (c >= 0x2160 && c <= 0x2183) ||
                (c >= 0x2336 && c <= 0x237A) ||
                (c == 0x2395) ||
                (c >= 0x249C && c <= 0x24E9) ||
                (c >= 0x3005 && c <= 0x3007) ||
                (c >= 0x3021 && c <= 0x3029) ||
                (c >= 0x3031 && c <= 0x3035) ||
                (c >= 0x3038 && c <= 0x303C) ||
                (c >= 0x3041 && c <= 0x3096) ||
                (c >= 0x309D && c <= 0x309F) ||
                (c >= 0x30A1 && c <= 0x30FA) ||
                (c >= 0x30FC && c <= 0x30FF) ||
                (c >= 0x3105 && c <= 0x312C) ||
                (c >= 0x3131 && c <= 0x318E) ||
                (c >= 0x3190 && c <= 0x31B7) ||
                (c >= 0x31F0 && c <= 0x321C) ||
                (c >= 0x3220 && c <= 0x3243) ||
                (c >= 0x3260 && c <= 0x327B) ||
                (c >= 0x327F && c <= 0x32B0) ||
                (c >= 0x32C0 && c <= 0x32CB) ||
                (c >= 0x32D0 && c <= 0x32FE) ||
                (c >= 0x3300 && c <= 0x3376) ||
                (c >= 0x337B && c <= 0x33DD) ||
                (c >= 0x33E0 && c <= 0x33FE) ||
                (c >= 0x3400 && c <= 0x4DB5) ||
                (c >= 0x4E00 && c <= 0x9FA5) ||
                (c >= 0xA000 && c <= 0xA48C) ||
                (c >= 0xAC00 && c <= 0xD7A3) ||
                (c >= 0xD800 && c <= 0xFA2D) ||
                (c >= 0xFA30 && c <= 0xFA6A) ||
                (c >= 0xFB00 && c <= 0xFB06) ||
                (c >= 0xFB13 && c <= 0xFB17) ||
                (c >= 0xFF21 && c <= 0xFF3A) ||
                (c >= 0xFF41 && c <= 0xFF5A) ||
                (c >= 0xFF66 && c <= 0xFFBE) ||
                (c >= 0xFFC2 && c <= 0xFFC7) ||
                (c >= 0xFFCA && c <= 0xFFCF) ||
                (c >= 0xFFD2 && c <= 0xFFD7) ||
                (c >= 0xFFDA && c <= 0xFFDC) ||
                (c >= 0x10300 && c <= 0x1031E) ||
                (c >= 0x10320 && c <= 0x10323) ||
                (c >= 0x10330 && c <= 0x1034A) ||
                (c >= 0x10400 && c <= 0x10425) ||
                (c >= 0x10428 && c <= 0x1044D) ||
                (c >= 0x1D000 && c <= 0x1D0F5) ||
                (c >= 0x1D100 && c <= 0x1D126) ||
                (c >= 0x1D12A && c <= 0x1D166) ||
                (c >= 0x1D16A && c <= 0x1D172) ||
                (c >= 0x1D183 && c <= 0x1D184) ||
                (c >= 0x1D18C && c <= 0x1D1A9) ||
                (c >= 0x1D1AE && c <= 0x1D1DD) ||
                (c >= 0x1D400 && c <= 0x1D454) ||
                (c >= 0x1D456 && c <= 0x1D49C) ||
                (c >= 0x1D49E && c <= 0x1D49F) ||
                (c == 0x1D4A2) ||
                (c >= 0x1D4A5 && c <= 0x1D4A6) ||
                (c >= 0x1D4A9 && c <= 0x1D4AC) ||
                (c >= 0x1D4AE && c <= 0x1D4B9) ||
                (c == 0x1D4BB) ||
                (c >= 0x1D4BD && c <= 0x1D4C0) ||
                (c >= 0x1D4C2 && c <= 0x1D4C3) ||
                (c >= 0x1D4C5 && c <= 0x1D505) ||
                (c >= 0x1D507 && c <= 0x1D50A) ||
                (c >= 0x1D50D && c <= 0x1D514) ||
                (c >= 0x1D516 && c <= 0x1D51C) ||
                (c >= 0x1D51E && c <= 0x1D539) ||
                (c >= 0x1D53B && c <= 0x1D53E) ||
                (c >= 0x1D540 && c <= 0x1D544) ||
                (c == 0x1D546) ||
                (c >= 0x1D54A && c <= 0x1D550) ||
                (c >= 0x1D552 && c <= 0x1D6A3) ||
                (c >= 0x1D6A8 && c <= 0x1D7C9) ||
                (c >= 0x20000 && c <= 0x2A6D6) ||
                (c >= 0x2F800 && c <= 0x2FA1D) ||
                (c >= 0xF0000 && c <= 0xFFFFD) ||
                (c >= 0x100000 && c <= 0x10FFFD));
        }

        public static bool IsRandALCat(int c)
        {
            return (
                (c == 0x05BE) ||
                (c == 0x05C0) ||
                (c == 0x05C3) ||
                (c >= 0x05D0 && c <= 0x05EA) ||
                (c >= 0x05F0 && c <= 0x05F4) ||
                (c == 0x061B) ||
                (c == 0x061F) ||
                (c >= 0x0621 && c <= 0x063A) ||
                (c >= 0x0640 && c <= 0x064A) ||
                (c >= 0x066D && c <= 0x066F) ||
                (c >= 0x0671 && c <= 0x06D5) ||
                (c == 0x06DD) ||
                (c >= 0x06E5 && c <= 0x06E6) ||
                (c >= 0x06FA && c <= 0x06FE) ||
                (c >= 0x0700 && c <= 0x070D) ||
                (c == 0x0710) ||
                (c >= 0x0712 && c <= 0x072C) ||
                (c >= 0x0780 && c <= 0x07A5) ||
                (c == 0x07B1) ||
                (c == 0x200F) ||
                (c == 0xFB1D) ||
                (c >= 0xFB1F && c <= 0xFB28) ||
                (c >= 0xFB2A && c <= 0xFB36) ||
                (c >= 0xFB38 && c <= 0xFB3C) ||
                (c == 0xFB3E) ||
                (c >= 0xFB40 && c <= 0xFB41) ||
                (c >= 0xFB43 && c <= 0xFB44) ||
                (c >= 0xFB46 && c <= 0xFBB1) ||
                (c >= 0xFBD3 && c <= 0xFD3D) ||
                (c >= 0xFD50 && c <= 0xFD8F) ||
                (c >= 0xFD92 && c <= 0xFDC7) ||
                (c >= 0xFDF0 && c <= 0xFDFC) ||
                (c >= 0xFE70 && c <= 0xFE74) ||
                (c >= 0xFE76 && c <= 0xFEFC));
        }

        public static bool IsTypeB(int c)
        {
            // Within a cue, paragraph boundaries are only denoted by Type B characters, such as U+000A LINE FEED (LF), U+0085 NEXT LINE (NEL), and U+2029 PARAGRAPH SEPARATOR. (This means each line of the cue is reordered as if it was a separate paragraph.)
            return (
                (c == 0x000A) ||
                (c == 0x0085) ||
                (c == 0x2029));
        }
    }
}
